package com.quo.mapper;

import com.order.hit.crossover.platform.common.dao.QuotationDao;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface QuotationMapper
{

    @Select("SELECT * FROM quotation")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
    List<QuotationDao> selectAll();


    @Select("SELECT * FROM quotation where order_id = #{orderId}")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
        //  查询某个订单关联的所有报价单
    List<QuotationDao> selectByOrderId(@Param("orderId") String orderId);


    @Select("SELECT * FROM quotation where quoted_type = #{type}")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
        //  查询某个类型的所有报价单
    List<QuotationDao> selectByType(@Param("type") String type);

    @Select("SELECT * FROM quotation where quoted_type = #{type} AND store_id = #{storeId}")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
        //  查询某个门店的某个类型的所有报价单
    List<QuotationDao> selectByTypeOfStore(@Param("type") String type, @Param("storeId") String storeId);


    @Select("SELECT * FROM quotation where quotation_id = #{quotationId}")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
        //  按ID查询报价单
    QuotationDao selectById(@Param("quotationId") String quotationId);


    @Insert("insert into quotation(quotation_id, quoted_type, quoted_state, " +
            "store_id, store_name, store_location, " +
            "goodId, good_name, good_type, spec, wholeSalePrice, retailPrice, validDate, " +
            "quoted_price, good_number, start_time, end_time, order_id) " +
            "values(#{quotationId}, #{quotedType}, #{quotedState}, " +
            "#{storeId}, #{storeName}, #{storeLocation}," +
            "#{goodId}, #{goodName}, #{goodType}, #{spec}, #{wholeSalePrice}, #{retailPrice}, #{validDate}, " +
            "#{quotedPrice},#{goodNumber},#{start_time}, #{end_time}, #{orderId})")
    @Results({
            @Result(property = "quotationId", column = "quotation_id"),
            @Result(property = "quotedType", column = "quoted_type"),
            @Result(property = "quotedState", column = "quoted_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "quotedPrice", column = "quoted_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time"),
            @Result(property = "orderId", column = "order_id")
    })
    void add(QuotationDao quotationDao);

    @Update("update quotation set " +
            "quoted_type=#{quotedType}, quoted_state=#{quotedState}, " +
            "store_id=#{storeId}, store_name=#{storeName}, store_location=#{storeLocation}, " +
            "goodId=#{goodId}, good_name=#{goodName}, good_type=#{goodType}, spec=#{spec}, wholeSalePrice=#{wholeSalePrice}, retailPrice=#{retailPrice}, validDate=#{validDate}, " +
            "quoted_price=#{quotedPrice}, good_number=#{goodNumber}, start_time=#{start_time}, end_time=#{end_time}, order_id=#{orderId} " +
            "where quotation_id = #{quotationId}")
    void update(QuotationDao quotationDao);


    @Delete("delete from quotation where quotation_id = #{quotationId}")
    void deletebyId(@Param("quotationId") String quotationId);


    @Delete("delete from quotation where order_id = #{orderId}")
        //  删除某个order关联的所有报价单
    void deletebyOrderId(@Param("orderId") String orderId);

}
